const explain = require("explain")
const uniID = require('uni-id')

module.exports = class auth extends explain.service {
	async sendSmsCode(params) {
		const {
			mobile
		} = params
		const randomStr = '00000' + Math.floor(Math.random() * 1000000)
		const code = randomStr.substring(randomStr.length - 6)
		// const res = await uniID.sendSmsCode({
		// 	mobile,
		// 	code,
		// 	type: 'login'
		// })
		const res = await uniID.setVerifyCode({
			mobile,
			code,
			expiresIn: 180,
			type: 'login'
		})
		return {
			smsCode: code,
			...res
		}
	}

	async login(params) {
		return await uniID.loginBySms(params)
	}

	async checkToken(params) {
		return await uniID.checkToken(params.token)
	}
}
